/*
 * Pabudr_seView.java
 */

package pabudr_se;

import java.awt.Component;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * The application's main frame.
 */
public class Pabudr_seView extends FrameView {

    public static final boolean DEBUG = DebugStatus.DEBUG;
    public static final boolean RANDOM = DebugStatus.RANDOM;
    public Pabudr_seView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = Pabudr_seApp.getApplication().getMainFrame();
            aboutBox = new Pabudr_seAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        Pabudr_seApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        simulation_cfg = new javax.swing.JTabbedPane();
        atom_cfg = new javax.swing.JTabbedPane();
        atom_cfg1 = new pabudr_se.AtomCfgPanel();
        atom_cfg2 = new pabudr_se.AtomCfgPanel();
        atom_cfg3 = new pabudr_se.AtomCfgPanel();
        barrier_cfg = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        startX = new javax.swing.JTextField();
        startY = new javax.swing.JTextField();
        endX = new javax.swing.JTextField();
        endY = new javax.swing.JTextField();
        addBarierButton = new javax.swing.JButton();
        atomPanel1 = pabudr_se.AtomPanel.getAtomPanel();
        startButton = new javax.swing.JButton();
        pauseButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        simulation_cfg.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        simulation_cfg.setName("simulation_cfg"); // NOI18N

        atom_cfg.setName("atom_cfg"); // NOI18N

        atom_cfg1.setBorder(null);
        atom_cfg1.setName("atom_cfg1"); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(Pabudr_seView.class);
        atom_cfg.addTab(resourceMap.getString("atom_cfg1.TabConstraints.tabTitle"), atom_cfg1); // NOI18N

        atom_cfg2.setBorder(null);
        atom_cfg2.setName("atom_cfg2"); // NOI18N
        atom_cfg.addTab(resourceMap.getString("atom_cfg2.TabConstraints.tabTitle"), atom_cfg2); // NOI18N

        atom_cfg3.setBorder(null);
        atom_cfg3.setName("atom_cfg3"); // NOI18N
        atom_cfg.addTab(resourceMap.getString("atom_cfg3.TabConstraints.tabTitle"), atom_cfg3); // NOI18N

        simulation_cfg.addTab(resourceMap.getString("atom_cfg.TabConstraints.tabTitle"), atom_cfg); // NOI18N

        barrier_cfg.setName("barrier_cfg"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        startX.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        startX.setText(resourceMap.getString("startX.text")); // NOI18N
        startX.setName("startX"); // NOI18N

        startY.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        startY.setText(resourceMap.getString("startY.text")); // NOI18N
        startY.setName("startY"); // NOI18N

        endX.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        endX.setText(resourceMap.getString("endX.text")); // NOI18N
        endX.setName("endX"); // NOI18N
        endX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                endXActionPerformed(evt);
            }
        });

        endY.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        endY.setText(resourceMap.getString("endY.text")); // NOI18N
        endY.setName("endY"); // NOI18N
        endY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                endYActionPerformed(evt);
            }
        });

        addBarierButton.setText(resourceMap.getString("addBarierButton.text")); // NOI18N
        addBarierButton.setName("addBarierButton"); // NOI18N
        addBarierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addBarierButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout barrier_cfgLayout = new javax.swing.GroupLayout(barrier_cfg);
        barrier_cfg.setLayout(barrier_cfgLayout);
        barrier_cfgLayout.setHorizontalGroup(
            barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(barrier_cfgLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addBarierButton)
                    .addGroup(barrier_cfgLayout.createSequentialGroup()
                        .addGroup(barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(endY, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                            .addComponent(endX, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                            .addComponent(startY, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                            .addComponent(startX, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE))))
                .addGap(40, 40, 40))
        );
        barrier_cfgLayout.setVerticalGroup(
            barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(barrier_cfgLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(startX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(startY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addGroup(barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(endX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(barrier_cfgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(endY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addComponent(addBarierButton)
                .addContainerGap())
        );

        simulation_cfg.addTab(resourceMap.getString("barrier_cfg.TabConstraints.tabTitle"), barrier_cfg); // NOI18N

        atomPanel1.setBackground(resourceMap.getColor("atomPanel1.background")); // NOI18N
        atomPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 10));
        atomPanel1.setName("atomPanel1"); // NOI18N

        javax.swing.GroupLayout atomPanel1Layout = new javax.swing.GroupLayout(atomPanel1);
        atomPanel1.setLayout(atomPanel1Layout);
        atomPanel1Layout.setHorizontalGroup(
            atomPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 256, Short.MAX_VALUE)
        );
        atomPanel1Layout.setVerticalGroup(
            atomPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 354, Short.MAX_VALUE)
        );

        startButton.setText(resourceMap.getString("startButton.text")); // NOI18N
        startButton.setName("startButton"); // NOI18N
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });

        pauseButton.setText(resourceMap.getString("pauseButton.text")); // NOI18N
        pauseButton.setEnabled(false);
        pauseButton.setName("pauseButton"); // NOI18N
        pauseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pauseButtonActionPerformed(evt);
            }
        });

        stopButton.setText(resourceMap.getString("stopButton.text")); // NOI18N
        stopButton.setEnabled(false);
        stopButton.setName("stopButton"); // NOI18N
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(pauseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(atomPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(simulation_cfg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(atomPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(simulation_cfg, javax.swing.GroupLayout.PREFERRED_SIZE, 374, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startButton)
                    .addComponent(pauseButton)
                    .addComponent(stopButton)))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem2);

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem1);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem3);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 443, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents


    // Startbutton auf der Bedienoberflaeche
    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
        //System.out.println(atom_cfg.getFocusCycleRootAncestor());
        // liest settings fÃ¼r 3 atomarten aus
        //atom_cfg1.getCfgSettings();
        //atom_cfg3.getCfgSettings();
        //atom_cfg2.getCfgSettings();
       
        // Erlaubt dem Thread Simulationen zu starten

       if (AtomPanel.getAtomPanel().getSettings().list_atome.isEmpty())
       {
           JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "There are no atoms present. Not started");
           return;
       }

       started = true;
       if(DEBUG)
       {
            System.out.println("Sim started");
       }

       setEnabledCfgPanel(false);

       // besorgt zufaellige simulationseinstellungen
       // ueberschreibt dazu aktuelle einstellungen des AtomPanels
       if(RANDOM)
       {
            final ArrayList<Atom> a;
            a =(ArrayList<Atom>)AtomPanel.createRandomAtoms(50, 600f, 400f, 1f, 1f, 10f, 5f, 90f, 120f);
            //a =(ArrayList<Atom>)AtomPanel.createRandomAtoms(1, 600f, 400f, 1f, 1f, 10f, 5f, 1f, 1f);
       
            Settings s = atomPanel1.getSettings();
            s.list_atome = a;
            atomPanel1.setSettings(s);
       }

       //atomPanel1.setBackground(Color.LIGHT_GRAY);
       //Thread der SImulation startet und auf panel zeichnet
    new Thread(new RunSimulator()).start();

    //start button abschalten und pause/stop aktivieren
    startButton.setEnabled(false);
    pauseButton.setEnabled(true);
    stopButton.setEnabled(true);


    }//GEN-LAST:event_startButtonActionPerformed

    // Einstellungen laden Eintrag im Menu der Bedienoberflaeche
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        if(DEBUG)
        {
            System.out.println("loadSettings pressed");
        }
        
        // Settings lesen
        final Settings loadedSets = fileIO.loadSettings();
        
        // Settings laden
        if( loadedSets != null)
        {
            // neue Settings laden
            atomPanel1.setSettings(loadedSets);
            // Panel aktualisieren
            atomPanel1.repaint();
        }
        
    }//GEN-LAST:event_jMenuItem2ActionPerformed



    // About eintrag im Menue der Bedienoberflaeche
    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        showAboutBox();
    }//GEN-LAST:event_aboutMenuItemActionPerformed



    // Beenden eintrag im Menue der Bedienoberflaeche
    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed


    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        try {
            fileIO.saveSettings(atomPanel1.getSettings());
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Pabudr_seView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Pabudr_seView.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jMenuItem1ActionPerformed




    // Aomspuren speichern im Menue der Bedienoberflaeche
    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // besorgt speichern des bildes 
        fileIO.saveImage(atomPanel1.getImage());
}//GEN-LAST:event_jMenuItem3ActionPerformed



    private void endXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_endXActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_endXActionPerformed



    private void endYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_endYActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_endYActionPerformed



    // Barrieren hinzufuegen Butten im Barriers Panel der Bedienoberflaeche
    private void addBarierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBarierButtonActionPerformed
        // Hinzufuegen von Barrieren
        // nur im Zustand STOP
       //if(started) return;

        //Koordinaten der Barriere
        final float x1, y1, x2, y2;

        try
        {
        //Startpkt setzten
        x1 = castToFloat(startX.getText());
        y1 = castToFloat(startY.getText());
        //Endpkt setzen
        x2 = castToFloat(endX.getText());
        y2 = castToFloat(endY.getText());

        }
        catch (NumberFormatException e)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Input Error.");
            return;
        }
        final Simulator sim = new Simulator(AtomPanel.getAtomPanel());

        //atomPanel settings um eine barriere erweitern, wenn eingaben korrekt
        Barrier newBarrier = new Barrier(x1,y1,x2,y2);

        for (Atom a : sim.list_atome)
        {
            if (sim.barrierAtomIntersect(a, newBarrier))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Barrier collides with an atom.");
                return;
            }
        }

        //AtomPanel settings modifizieren
        Settings settings = atomPanel1.getSettings();
        ArrayList<Barrier> barriers = settings.list_barrieren;
        //barriere noch nicht enthalten
        if(!barriers.contains(newBarrier))
        {
            barriers.add(newBarrier);
            settings.list_barrieren = barriers;
            atomPanel1.setSettings(settings);
            atomPanel1.repaint();
        }


    }//GEN-LAST:event_addBarierButtonActionPerformed



    private Float castToFloat(String str){
        return Float.parseFloat(str);
    }
// Pausebutton auf der Bedienoberflaeche
    private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseButtonActionPerformed
        //button wird wÃ¤hrend laufender sim gedrÃ¼ckt
        setEnabledCfgPanel(!pause);
        // cfgPanels die teilweise gesperrt waren wieder sperren
        AtomCfgPanel.allowAtomConfiguration(atom_cfg1, atom_cfg2, atom_cfg3);
        if( !pause )
        {
            // Pause aktiv, beschriftung aendern
            pause = true;
            pauseButton.setText("Resume");
        }else
        {
            // Pause modus verlassen, beschriftung zuruecksetzen
            pause = false;
            pauseButton.setText("Pause");
        }
    }//GEN-LAST:event_pauseButtonActionPerformed

  

    // Stopbutton auf der Bedienoberflaeche
    private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed

        // wirklich beenden, und einstellungen verwerfen?
        final int usr_in = JOptionPane.showConfirmDialog(null, "This will clear the current Simulation\n" +
                "Are you sure?");
        

        if( usr_in != 0)
        {
            return;
        }

        setEnabledCfgPanel(true);
         // Simulationsstatus auf beendet setzen
        // --> beendet fuer simulation zustaendigen thread
        started = false;
        // Pause modus abschalten
        pause = false;
        // fals in pause beendet wurde is button txt falsch
        pauseButton.setText("Pause");
        // Simulationsflaeche leeren
        atomPanel1.clearView();

        // Simulationsstart erlauben
        startButton.setEnabled(true);
        // Beenden von Simulation verbieten
        stopButton.setEnabled(false);
        // Pause modus verbieten
        pauseButton.setEnabled(false);

        
    }//GEN-LAST:event_stopButtonActionPerformed

    private void setEnabledCfgPanel(final boolean enable)
    {
      this.atomPanel1.isRunning = !enable;

      this.simulation_cfg.setEnabled(enable);
      this.atom_cfg.setEnabled(enable);

      // BarrierenPanel Inhalt iterieren
      for(Component c : barrier_cfg.getComponents())
          c.setEnabled(enable);


      //iteriere ueber alle AtomCfgPanels
      for (Component cfg : atom_cfg.getComponents())
      {
          cfg.setEnabled(enable);
          if (cfg instanceof AtomCfgPanel)
          {
              //iteriere alle UnterKompenenten
              for (Component c : ((AtomCfgPanel)cfg).getComponents())
              {
                  c.setEnabled(enable);
              }
          }
      }
    }

   private class RunSimulator implements Runnable
   {
       // Simulator mit AtomPanel anlegen
       protected Simulator sim = new Simulator(Pabudr_seView.this.atomPanel1);
       

       public void run()
       {
         while (Pabudr_seView.this.started )
         {
            if(pause)
            {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Pabudr_seView.class.getName()).log(Level.SEVERE, null, ex);
                }
            //damit solange gepennt wird bis pause = false
            }else
            {
                sim.update();
                //System.out.println("sim updated");
                atomPanel1.repaint();
                try {
                    Thread.sleep(Simulator.SLEEPTIME);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Pabudr_seView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            }
       }
   }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addBarierButton;
    private pabudr_se.AtomPanel atomPanel1;
    private javax.swing.JTabbedPane atom_cfg;
    private pabudr_se.AtomCfgPanel atom_cfg1;
    private pabudr_se.AtomCfgPanel atom_cfg2;
    private pabudr_se.AtomCfgPanel atom_cfg3;
    private javax.swing.JPanel barrier_cfg;
    private javax.swing.JTextField endX;
    private javax.swing.JTextField endY;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JButton pauseButton;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JTabbedPane simulation_cfg;
    private javax.swing.JButton startButton;
    private javax.swing.JTextField startX;
    private javax.swing.JTextField startY;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JButton stopButton;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;

    private boolean started = false, pause = false; //zeigt satatus der sim
    private final FileIO fileIO = new FileIO(); //speichern/laden von Settings
    
}
